import { createStore } from 'vuex';
import { userConfig } from './config/userConfig';


export default createStore({
  state: {
    watchlist: []
  },
  mutations: {
    setWatchlist(state, watchlist) {
      state.watchlist = watchlist;
    }
  },
  actions: {
    updateWatchlist({ commit }) {
      fetch(`/api/favorite/stocks?user_id=${userConfig.userId}`)
        .then(response => response.json())
        .then(data => {
          commit('setWatchlist', data.data);
        })
        .catch(error => console.error('Failed to update watchlist:', error));
    }
  }
});